//
//  File.swift
//  DemoTest
//
//  Created by 韦小新 on 2022/4/22.
//


//MARK: 

import SwiftUI

struct SwiftUIView: View {
    
    @State var isStart = false
    @State var step1 = false
    @State var step2 = false
    @State var step3 = false
    var body: some View {
        ZStack {
            Image("Background")
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
                .overlay(
                    VStack {
                    Spacer()
                    HStack{
                        Spacer()
                        Text("Click  screen to start the game ")
                            .font(.custom("Bradley Hand Bold", size: 50))
                    }
                    
                })
//            Image("boy1")
            Image("boy1")
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: 300, height: 400)
                .offset(x: step1 ? 120 : -200, y: step1 ? 300 : 350)
                .scaleEffect(step1 ? 0.7 : 1)

                .offset(x: step2 ? -220 : 0, y: step2 ? 40 : 0)
                .scaleEffect(step2 ? 0.6 : 1)


                .offset(x: step3 ? 112 : 0, y: step3 ? -60 : 0)
            
            
        }
        .onAppear(){
            alwaysPlayAudio(forResource: "date", ofType: "mp3")
        }
        .fullScreenCover(isPresented: self.$isStart, content: {PassOnew()})
        .onTapGesture {
            withAnimation(.easeInOut(duration: 2)){
                step1 = true
                DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2)) {
                    withAnimation(.easeInOut(duration: 2)){
                        step2 = true
                        DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) {
                            
                            withAnimation(.easeInOut(duration: 2)) {
                                step3 = true
                                DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
                                    isStart = true
                                }
                            }
                            
                        }
                    }
                }
                
            }
        }


            
    }
    
}

//struct Boy: View {
//
//    let images = ["boy1", "boy2", "boy3"]
//
//    @State private var idx = 0
//
//    private let timer = Timer.publish(every: 0.5, on: .main, in: .common).autoconnect()
//
//    var transition: AnyTransition = .identity
//
//    var body: some View {
//        ZStack {
//            ForEach(images.indices, id: \.self) { index in
//                if self.idx == index {
//                    Image(self.images[index])
//                        .resizable()
//                        .aspectRatio( contentMode: .fit)
//                        .frame(width: 300, height: 400)
//                                        }
//            }
//
//
//        }.onReceive(timer) { _ in
//            withAnimation {
//                self.idx = self.idx < (self.images.count - 1) ? self.idx + 1 : 0
//            }
//        }
//    }
//}
struct SwiftUIView_Previews: PreviewProvider {
    static var previews: some View {
        
        SwiftUIView()
            .previewInterfaceOrientation(.landscapeLeft)
        
    }
    
}
//
